package com.briup.smartcity_group7.web.controller;

import com.briup.smartcity_group7.bean.basic.BaseConfig;
import com.briup.smartcity_group7.log.Logging;
import com.briup.smartcity_group7.service.IBaseConfigService;
import com.briup.smartcity_group7.util.Result;
import com.briup.smartcity_group7.util.ResultUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Logging()
@Api(tags = "系统配置模块")
@RequestMapping("/auth/config")
@RestController
public class BaseConfigController {

    @Autowired
    private IBaseConfigService service;
    private Object pageInfo;

    @Logging()
    @ApiOperation("保存配置信息")
    @PostMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "configIcon"),
            @ApiImplicitParam(name = "configInfo"),
            @ApiImplicitParam(name = "configName"),
    })
    public  Result saveConfig(BaseConfig baseConfig){
        service.saveConfig(baseConfig);
        return ResultUtil.success("success");
    }

    @Logging()
    @ApiOperation("更新配置")
    @PutMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "configIcon"),
            @ApiImplicitParam(name = "configId",dataType = "int"),
            @ApiImplicitParam(name = "configInfo"),
            @ApiImplicitParam(name = "configName"),
    })
    public Result updateConfig(BaseConfig baseConfig){
        service.updateConfig(baseConfig);
        return ResultUtil.success("success");
    }

    @Logging()
    @ApiOperation("更新配置信息状态")
    @PutMapping("/status")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id"),
            @ApiImplicitParam(name = "status",value = "status")
    })
    public Result upConfig(Integer id,Integer status){
        service.changeConfigStatus(id,status);
        return ResultUtil.success("success");
    }

    @Logging()
    @ApiOperation("通过id删除配置信息")
    @DeleteMapping
    @ApiImplicitParam(name = "id",value = "id",dataType = "int")
    public Result deleteConfig(Integer id){
        int i = service.deleteById(id);
        return  ResultUtil.success("success");
    }

    @Logging()
    @ApiOperation("分页查询配置信息")
    @GetMapping ("/page")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum",value = "pageNum"),
            @ApiImplicitParam(name = "pageSize",value = "pageSize")
    })
    public Result findConfig(Integer pageNum,Integer pageSize){
        PageInfo<BaseConfig> pageInfo = service.findAllWithPage(pageNum, pageSize);
        return ResultUtil.success(pageInfo);
    }

    @Logging()
    @GetMapping("/yes")
    @ApiOperation("查询当前启用的系统配置")
    public Result Config(){

        BaseConfig baseConfig = service.currentConfigYes();
        System.out.println(baseConfig);
        return ResultUtil.success("success");
    }
}
